package com.wzz.seckillone.activeMq.base;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @ProjectName: seckillOne
 * @Package: com.wzz.seckillone.activeMq
 * @ClassName: QueueProduce
 * @Author: wzz
 * @Description:
 * @Date: 2022/3/21 9:02
 * @Version: 1.0
 */
public class QueueProduce {
    private static final String ACTIVEMQ_URL = "tcp://192.168.1.104:61616";
    private static final String queueName = "queueOne";

    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ACTIVEMQ_URL);
        Connection connection = connectionFactory.createConnection();
        connection.start();
        /*activemq的事务  手动提交*/
        Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(queueName);
        MessageProducer producer = session.createProducer(queue);
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        try {
            TextMessage niaho = session.createTextMessage("niaho");
            producer.send(niaho);
            session.commit();
        }catch (Exception e){
            session.rollback();
        }finally {
            session.close();
            connection.close();
        }

    }

}
